﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.WebControls;
using NetDon.eBoss.Data.EntityClasses;
using NetDon.Utilities;
using NetDon.WebControls;
using NetDon.eBoss.Data.EntityClasses;

namespace NetDon.OA.Portal.HtmlTool
{
    public partial class BatchTagEdit : NetDonPage
    {
        protected IList<int?> Ids
        {
            get
            {
                if (string.IsNullOrWhiteSpace(this.fieldIds.Value))
                    return new List<int?>();
                return this.fieldIds.Value.Split(new char[] { ',' }).Select(id => id.ToInt32()).ToList();

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CancelButton = btnCancel;


            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            foreach (var id in Ids)
            {
                if (id.HasValue)
                {
                    var group = new ProductgroupEntity(id.Value);

                    group.Tag = this.ddlRouteTypeId.SelectedValue.ToInt32();
                    group.Save();
                }
            }
            CloseWindow(true);


        }

        private void LoadInitialView()
        {
            if(Ids.Any())
            {
                foreach (var id in Ids)
                {
                    if(id.HasValue)
                    {
                        var group = new ProductgroupEntity();
                        group.FetchUsingPK(id.Value);
                        if(!string.IsNullOrWhiteSpace(group.Description))
                        {
                            this.ddlRouteTypeId.SelectedValue = group.Tag.ToString();
                            break;
                        }
                       
                    }
                }
            }

        }

        protected void btnReLoadIds_Click(object sender, EventArgs e)
        {
            LoadInitialView();
            btnReLoadIds.Enabled = false;
        }






    }
}